package com.heima.comment.controller;

import com.heima.comment.dtos.CommentLikeDto;
import com.heima.comment.dtos.CommentListDto;
import com.heima.comment.dtos.CommentSaveDto;
import com.heima.comment.service.CommentService;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评论控制器
 *
 * @author DiXiaoNie
 * @date 2023/01/05
 * @since 2023/1/5 10:16
 */
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 保存评论
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2023/01/05
     */
    @PostMapping("/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto) {
        return this.commentService.saveComment(dto);
    }

    /**
     * 评论列表
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2023/01/05
     */
    @PostMapping("/load")
    public ResponseResult findByArticleId(@RequestBody CommentListDto dto) {
        return this.commentService.findByArticleId(dto);
    }

    /**
     * 点赞或取消点赞
     *
     * @param dto dto
     * @return {@link ResponseResult }
     * @author DiXiaoNie
     * @date 2023/01/05
     */
    @PostMapping("/like")
    public ResponseResult likeOrUnLike(@RequestBody CommentLikeDto dto) {
        return this.commentService.likeOrUnLike(dto);
    }
}
